<?php
class Country_Widget_ProfileGroupsController extends Engine_Content_Widget_Abstract
{
  protected $_childCount;
  
  public function indexAction()
  {
    // Don't render this if not authorized
    $viewer = Engine_Api::_()->user()->getViewer();
	if( !$viewer->getIdentity() ) {
      return $this->setNoRender();
    }
	
    // Get paginator
    $membership = Engine_Api::_()->getDbtable('membership', 'group');
    $this->view->paginator = $paginator = Zend_Paginator::factory($membership->getMembershipsOfSelect($viewer));

    // Set item count per page and current page number
    $paginator->setItemCountPerPage($this->_getParam('itemCountPerPage', 100));
    $paginator->setCurrentPageNumber($this->_getParam('page', 1));

    // Do not render if nothing to show
    if( $paginator->getTotalItemCount() <= 0 ) {
      return $this->setNoRender();
    }
  }

  public function getChildCount()
  {
    return $this->_childCount;
  }
}